```html
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>深入理解JVM分层编译机制</title>
    <link rel="stylesheet" href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css">
    <link rel="stylesheet" href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            line-height: 1.8;
            color: #333;
            background-color: #f9f9f9;
        }
        .hero {
            background: linear-gradient(135deg, #6e8efb 0%, #a777e3 100%);
            color: white;
        }
        .drop-cap {
            font-size: 4.5rem;
            line-height: 1;
            float: left;
            margin-right: 0.5rem;
            margin-bottom: 0;
            font-weight: bold;
            color: #6e8efb;
        }
        .card {
            transition: all 0.3s ease;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
        }
        .card:hover {
            transform: translateY(-5px);
            box-shadow: 0 15px 20px rgba(0, 0, 0, 0.1);
        }
        .section-title {
            position: relative;
            padding-bottom: 0.5rem;
        }
        .section-title:after {
            content: '';
            position: absolute;
            bottom: 0;
            left: 0;
            width: 50px;
            height: 3px;
            background: linear-gradient(90deg, #6e8efb, #a777e3);
        }
        .nav-item {
            position: relative;
        }
        .nav-item:after {
            content: '';
            position: absolute;
            bottom: -2px;
            left: 0;
            width: 0;
            height: 2px;
            background: #6e8efb;
            transition: width 0.3s ease;
        }
        .nav-item:hover:after {
            width: 100%;
        }
        .footer-link:hover {
            color: #a777e3 !important;
        }
        .mermaid {
            background-color: white;
            border-radius: 0.5rem;
            padding: 1.5rem;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
        }
        .timeline-item {
            position: relative;
            padding-left: 2rem;
            margin-bottom: 2rem;
        }
        .timeline-item:before {
            content: '';
            position: absolute;
            left: 0;
            top: 0;
            width: 12px;
            height: 12px;
            border-radius: 50%;
            background: #6e8efb;
            z-index: 2;
        }
        .timeline-item:after {
            content: '';
            position: absolute;
            left: 5px;
            top: 12px;
            bottom: -2rem;
            width: 2px;
            background: #e2e8f0;
        }
        .timeline-item:last-child:after {
            display: none;
        }
        .comparison-table {
            border-collapse: separate;
            border-spacing: 0;
            width: 100%;
        }
        .comparison-table th {
            background-color: #6e8efb;
            color: white;
            padding: 1rem;
        }
        .comparison-table td {
            padding: 1rem;
            border-bottom: 1px solid #e2e8f0;
        }
        .comparison-table tr:nth-child(even) {
            background-color: #f8fafc;
        }
    </style>
</head>
<body class="antialiased">
    <!-- 导航栏 -->
    <nav class="bg-white shadow-sm sticky top-0 z-50">
        <div class="container mx-auto px-6 py-4">
            <div class="flex items-center justify-between">
                <a href="#" class="text-xl font-bold text-gray-800">JVM深度解析</a>
                <div class="hidden md:flex space-x-8">
                    <a href="#overview" class="nav-item text-gray-600 hover:text-gray-900">概述</a>
                    <a href="#levels" class="nav-item text-gray-600 hover:text-gray-900">编译层级</a>
                    <a href="#mechanism" class="nav-item text-gray-600 hover:text-gray-900">切换机制</a>
                    <a href="#optimization" class="nav-item text-gray-600 hover:text-gray-900">调优策略</a>
                    <a href="#comparison" class="nav-item text-gray-600 hover:text-gray-900">对比AOT</a>
                </div>
                <button class="md:hidden focus:outline-none">
                    <i class="fas fa-bars text-gray-600"></i>
                </button>
            </div>
        </div>
    </nav>

    <!-- Hero模块 -->
    <header class="hero py-20">
        <div class="container mx-auto px-6 text-center">
            <h1 class="text-4xl md:text-5xl font-bold mb-6">深入理解JVM分层编译机制</h1>
            <p class="text-xl md:text-2xl mb-8 max-w-3xl mx-auto">探索Java虚拟机如何通过智能编译策略平衡启动速度与运行性能</p>
            <div class="flex justify-center space-x-4">
                <a href="#overview" class="bg-white text-blue-600 px-6 py-3 rounded-full font-medium hover:bg-blue-50 transition duration-300">开始阅读</a>
                <a href="#comparison" class="border-2 border-white text-white px-6 py-3 rounded-full font-medium hover:bg-white hover:text-blue-600 transition duration-300">对比AOT</a>
            </div>
        </div>
    </header>

    <!-- 主要内容区 -->
    <main class="container mx-auto px-6 py-12">
        <!-- 引言部分 -->
        <section class="mb-20">
            <div class="flex items-center mb-6">
                <div class="w-12 h-1 bg-gradient-to-r from-blue-400 to-purple-500 mr-4"></div>
                <h2 class="text-2xl font-semibold text-gray-800">什么是分层编译？</h2>
            </div>
            <div class="pl-16">
                <p class="mb-6 text-gray-700 leading-relaxed">
                    <span class="drop-cap">如</span>果你曾经研究过 Java 的执行流程，可能会听说过即时编译器（JIT）的存在，JIT 编译器在运行时将字节码转换为机器码，从而加快程序的执行速度。但仅仅有一个编译器还不够，因为不同的方法在不同的执行场景中有着不同的优化需求。为了解决这个问题，JVM 引入了分层编译机制，它将编译任务交给不同层次的编译器来处理，达到在不同性能场景下的最佳平衡。
                </p>
                <figure class="my-8">
                    <img src="https://cdn.nlark.com/yuque/0/2024/png/21449790/1725936607044-39a5e387-5525-44d0-9141-b14a59a23cf6.png" alt="分层编译示意图" class="rounded-lg shadow-md w-full max-w-2xl mx-auto">
                    <figcaption class="text-center text-sm text-gray-500 mt-2">图1: JVM分层编译机制示意图</figcaption>
                </figure>
                <p class="text-gray-700 leading-relaxed">
                    分层编译的核心思想是通过将解释器、C1 编译器（客户端编译器）、以及 C2 编译器（服务端编译器）相结合，利用程序的执行热点来动态优化代码。这种优化不仅能提升程序的启动速度，还能在程序运行时进行深入的性能调优。接下来，我们将深入探讨分层编译的工作原理、各个层次编译器的具体作用，以及它们如何协作，帮助 JVM 实现高效的代码执行。
                </p>
            </div>
        </section>

        <!-- 概述部分 -->
        <section id="overview" class="mb-20">
            <div class="flex items-center mb-6">
                <div class="w-12 h-1 bg-gradient-to-r from-blue-400 to-purple-500 mr-4"></div>
                <h2 class="text-2xl font-semibold text-gray-800">分层编译概述</h2>
            </div>
            
            <div class="grid md:grid-cols-2 gap-8 mb-10">
                <div class="card bg-white p-6 rounded-lg shadow-sm">
                    <div class="flex items-center mb-4">
                        <div class="w-8 h-8 bg-blue-100 rounded-full flex items-center justify-center mr-3">
                            <i class="fas fa-history text-blue-600"></i>
                        </div>
                        <h3 class="text-xl font-semibold">分层编译的背景</h3>
                    </div>
                    <p class="text-gray-700">
                        在JVM的早期版本中，代码要么以解释执行模式运行，要么通过JIT编译成机器码。解释执行速度较慢，但编译开销小；而JIT编译生成的机器码性能高，但编译过程会占用较多的CPU资源，特别是在启动阶段时可能导致应用启动变慢。为解决这两者之间的权衡，Java 7引入了分层编译，通过在不同阶段对代码逐步优化，平衡性能和编译成本。
                    </p>
                </div>
                
                <div class="card bg-white p-6 rounded-lg shadow-sm">
                    <div class="flex items-center mb-4">
                        <div class="w-8 h-8 bg-purple-100 rounded-full flex items-center justify-center mr-3">
                            <i class="fas fa-cogs text-purple-600"></i>
                        </div>
                        <h3 class="text-xl font-semibold">基本原理</h3>
                    </div>
                    <p class="text-gray-700">
                        分层编译的核心思想是：不对所有代码一开始就进行深度优化，而是根据代码的执行频率（即"热点"）来逐步升级编译等级。分层编译通过解释执行开始，随着代码被频繁调用，JVM会逐步将其从低级编译器（如C1编译器）优化到高级编译器（如C2编译器）。这种渐进优化的方式能够在不影响启动时间的前提下，逐渐提升热点代码的性能。
                    </p>
                </div>
            </div>
            
            <div class="bg-white rounded-lg shadow-sm p-6 mb-10">
                <h3 class="section-title text-xl font-semibold mb-6">C1与C2编译器对比</h3>
                <div class="overflow-x-auto">
                    <table class="comparison-table">
                        <thead>
                            <tr>
                                <th class="rounded-tl-lg"></th>
                                <th>C1编译器 (客户端编译器)</th>
                                <th class="rounded-tr-lg">C2编译器 (服务端编译器)</th>
                            </tr>
                        </thead>
                        <tbody>
                            <tr>
                                <td class="font-medium">优化目标</td>
                                <td>快速生成优化较少的机器码</td>
                                <td>深度优化，追求最高性能</td>
                            </tr>
                            <tr>
                                <td class="font-medium">编译速度</td>
                                <td>快，低延迟</td>
                                <td>慢，高开销</td>
                            </tr>
                            <tr>
                                <td class="font-medium">优化技术</td>
                                <td>简单内联、死代码消除</td>
                                <td>逃逸分析、循环展开、去虚拟化等</td>
                            </tr>
                            <tr>
                                <td class="font-medium">适用阶段</td>
                                <td>Tier 1-3，启动和中期优化</td>
                                <td>Tier 4，长期热点代码优化</td>
                            </tr>
                            <tr>
                                <td class="font-medium">适用场景</td>
                                <td>对启动时间敏感的应用</td>
                                <td>长期运行的高性能服务器应用</td>
                            </tr>
                        </tbody>
                    </table>
                </div>
            </div>
            
            <div class="card bg-white p-6 rounded-lg shadow-sm">
                <div class="flex items-center mb-4">
                    <div class="w-8 h-8 bg-green-100 rounded-full flex items-center justify-center mr-3">
                        <i class="fas fa-chart-line text-green-600"></i>
                    </div>
                    <h3 class="text-xl font-semibold">分层编译的优势</h3>
                </div>
                <div class="grid md:grid-cols-3 gap-4">
                    <div class="p-4 border-l-4 border-blue-500 bg-blue-50">
                        <h4 class="font-medium mb-2">加快启动时间</h4>
                        <p class="text-sm text-gray-600">初始阶段主要依赖解释执行和轻量级的C1编译器，显著加快应用启动</p>
                    </div>
                    <div class="p-4 border-l-4 border-purple-500 bg-purple-50">
                        <h4 class="font-medium mb-2">逐步优化</h4>
                        <p class="text-sm text-gray-600">根据代码执行频率动态调整编译层次，热点代码得到深入优化</p>
                    </div>
                    <div class="p-4 border-l-4 border-green-500 bg-green-50">
                        <h4 class="font-medium mb-2">降低编译成本</h4>
                        <p class="text-sm text-gray-600">避免在启动阶段进行高开销编译，只在必要时深度优化</p>
                    </div>
                </div>
            </div>
        </section>

        <!-- 编译层级部分 -->
        <section id="levels" class="mb-20">
            <div class="flex items-center mb-6">
                <div class="w-12 h-1 bg-gradient-to-r from-blue-400 to-purple-500 mr-4"></div>
                <h2 class="text-2xl font-semibold text-gray-800">分层编译的级别</h2>
            </div>
            
            <div class="grid md:grid-cols-2 gap-8">
                <div>
                    <div class="mb-10">
                        <h3 class="section-title text-xl font-semibold mb-6">编译级别概览</h3>
                        <p class="text-gray-700 mb-6">
                            分层编译的级别（Tiered Compilation Levels）是JVM在执行代码时，依据代码执行频率和优化需求，逐步提升编译复杂度和优化程度的过程。每个级别对应不同的执行方式和编译深度，目的是在程序运行的不同阶段根据需求应用不同层次的优化，从而平衡性能和编译开销。
                        </p>
                        <figure class="my-8">
                            <img src="https://cdn.nlark.com/yuque/0/2024/png/21449790/1725936659836-2a14070d-9be0-42ea-b7e1-08f03a15597b.png" alt="分层编译级别示意图" class="rounded-lg shadow-md w-full">
                            <figcaption class="text-center text-sm text-gray-500 mt-2">图2: 分层编译级别示意图</figcaption>
                        </figure>
                    </div>
                    
                    <div class="bg-white rounded-lg shadow-sm p-6 mb-8">
                        <h3 class="section-title text-xl font-semibold mb-6">级别切换机制</h3>
                        <div class="timeline-item">
                            <h4 class="font-semibold text-lg mb-2">热点探测</h4>
                            <p class="text-gray-700">JVM通过计数器等机制探测热点方法，当某个方法的执行次数超过某个阈值时，将其交由C1或C2编译器进行进一步优化。</p>
                        </div>
                        <div class="timeline-item">
                            <h4 class="font-semibold text-lg mb-2">反馈回路</h4>
                            <p class="text-gray-700">C1和C2编译器之间有协作机制，C1编译器会为C2收集运行时数据，而C2编译器也会根据实际的执行情况调整优化策略。</p>
                        </div>
                    </div>
                </div>
                
                <div>
                    <div class="bg-white rounded-lg shadow-sm p-6 mb-6">
                        <h3 class="section-title text-xl font-semibold mb-6">各层级详细说明</h3>
                        
                        <div class="mb-6">
                            <div class="flex items-center mb-2">
                                <span class="bg-blue-100 text-blue-800 text-sm font-semibold mr-2 px-2.5 py-0.5 rounded">Tier 0</span>
                                <h4 class="font-semibold">解释执行</h4>
                            </div>
                            <p class="text-gray-700 text-sm pl-12">
                                所有方法在最初阶段通过解释器执行，不进行即时编译。特点是快速启动但性能较差，适用于应用启动初期。
                            </p>
                        </div>
                        
                        <div class="mb-6">
                            <div class="flex items-center mb-2">
                                <span class="bg-purple-100 text-purple-800 text-sm font-semibold mr-2 px-2.5 py-0.5 rounded">Tier 1</span>
                                <h4 class="font-semibold">C1编译器（无分析的轻量编译）</h4>
                            </div>
                            <p class="text-gray-700 text-sm pl-12">
                                对热点候选方法进行简单优化和编译，编译速度快但优化程度低，适用于短时间内执行多次的代码。
                            </p>
                        </div>
                        
                        <div class="mb-6">
                            <div class="flex items-center mb-2">
                                <span class="bg-green-100 text-green-800 text-sm font-semibold mr-2 px-2.5 py-0.5 rounded">Tier 2</span>
                                <h4 class="font-semibold">C1编译器（带分析的轻量编译）</h4>
                            </div>
                            <p class="text-gray-700 text-sm pl-12">
                                根据基本运行时分析信息进行轻度优化，如内联方法、消除死代码等，性能比Tier 1有所提升。
                            </p>
                        </div>
                        
                        <div class="mb-6">
                            <div class="flex items-center mb-2">
                                <span class="bg-yellow-100 text-yellow-800 text-sm font-semibold mr-2 px-2.5 py-0.5 rounded">Tier 3</span>
                                <h4 class="font-semibold">C1编译器（带分析和偏好优化）</h4>
                            </div>
                            <p class="text-gray-700 text-sm pl-12">
                                使用运行时偏好信息进行更多优化，如基于分支预测的代码路径优化，为C2编译器做准备。
                            </p>
                        </div>
                        
                        <div class="mb-6">
                            <div class="flex items-center mb-2">
                                <span class="bg-red-100 text-red-800 text-sm font-semibold mr-2 px-2.5 py-0.5 rounded">Tier 4</span>
                                <h4 class="font-semibold">C2编译器（深度优化）</h4>
                            </div>
                            <p class="text-gray-700 text-sm pl-12">
                                对长期热点代码进行深度优化，包括逃逸分析、方法内联、循环展开等，编译时间长但性能最高。
                            </p>
                        </div>
                    </div>
                    
                    <div class="card bg-white p-6 rounded-lg shadow-sm">
                        <h3 class="section-title text-xl font-semibold mb-6">编译级别可视化</h3>
                        <div class="mermaid">
                            graph TD
                                A[解释执行 Tier 0] -->|执行次数达到阈值| B[C1轻量编译 Tier 1]
                                B -->|执行频率增加| C[C1带分析编译 Tier 2]
                                C -->|偏好信息收集| D[C1偏好优化 Tier 3]
                                D -->|确定为长期热点| E[C2深度优化 Tier 4]
                                E -->|执行频率降低| D
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- 层级切换机制部分 -->
        <section id="mechanism" class="mb-20">
            <div class="flex items-center mb-6">
                <div class="w-12 h-1 bg-gradient-to-r from-blue-400 to-purple-500 mr-4"></div>
                <h2 class="text-2xl font-semibold text-gray-800">层级切换机制</h2>
            </div>
            
            <div class="grid md:grid-cols-2 gap-8">
                <div>
                    <div class="bg-white rounded-lg shadow-sm p-6 mb-6">
                        <h3 class="section-title text-xl font-semibold mb-6">基础概念</h3>
                        <p class="text-gray-700 mb-4">
                            层级切换机制是JVM在运行时根据<strong>方法的执行频率</strong>、<strong>性能表现</strong>和<strong>热点探测结果</strong>，动态决定代码是否需要从一个层级切换到另一个层级。
                        </p>
                        <div class="bg-blue-50 border-l-4 border-blue-500 p-4 mb-4">
                            <div class="flex">
                                <div class="flex-shrink-0">
                                    <i class="fas fa-info-circle text-blue-500"></i>
                                </div>
                                <div class="ml-3">
                                    <p class="text-sm text-blue-700">
                                        分层编译中的层级包括：解释执行（Tier 0）、C1编译器（Tier 1到Tier 3）和C2编译器（Tier 4）。
                                    </p>
                                </div>
                            </div>
                        </div>
                    </div>
                    
                    <div class="card bg-white p-6 rounded-lg shadow-sm">
                        <h3 class="section-title text-xl font-semibold mb-6">热点探测与执行计数</h3>
                        <ul class="space-y-4">
                            <li class="flex items-start">
                                <span class="flex-shrink-0 bg-blue-100 text-blue-600 p-1 rounded-full mr-3">
                                    <i class="fas fa-search w-4 h-4"></i>
                                </span>
                                <span class="text-gray-700">
                                    <strong>初始执行与计数：</strong>方法首次执行时处于Tier 0状态，JVM为每个方法维护计数器记录执行次数。
                                </span>
                            </li>
                            <li class="flex items-start">
                                <span class="flex-shrink-0 bg-purple-100 text-purple-600 p-1 rounded-full mr-3">
                                    <i class="fas fa-sliders-h w-4 h-4"></i>
                                </span>
                                <span class="text-gray-700">
                                    <strong>阈值设定：</strong>当方法执行计数器达到预设阈值时，JVM判断为"热点候选"，触发从Tier 0到Tier 1的切换。
                                </span>
                            </li>
                            <li class="flex items-start">
                                <span class="flex-shrink-0 bg-green-100 text-green-600 p-1 rounded-full mr-3">
                                    <i class="fas fa-project-diagram w-4 h-4"></i>
                                </span>
                                <span class="text-gray-700">
                                    <strong>分支预测：</strong>JVM通过运行时收集的偏好数据（分支预测、方法调用频率等）决定是否提升优化层级。
                                </span>
                            </li>
                        </ul>
                    </div>
                </div>
                
                <div>
                    <div class="card bg-white p-6 rounded-lg shadow-sm mb-6">
                        <h3 class="section-title text-xl font-semibold mb-6">升级路径</h3>
                        <div class="space-y-4">
                            <div class="p-4 bg-blue-50 rounded-lg">
                                <h4 class="font-semibold mb-2">解释执行 → 轻量编译</h4>
                                <p class="text-sm text-gray-700">方法达到执行次数阈值后，由解释执行切换到C1轻量级编译，编译时间短，性能提升适中。</p>
                            </div>
                            <div class="p-4 bg-purple-50 rounded-lg">
                                <h4 class="font-semibold mb-2">轻量编译 → 带分析编译</h4>
                                <p class="text-sm text-gray-700">执行频率继续增加时，升级到Tier 2/3，引入运行时信息分析和偏好优化。</p>
                            </div>
                            <div class="p-4 bg-green-50 rounded-lg">
                                <h4 class="font-semibold mb-2">带分析编译 → 深度优化</h4>
                                <p class="text-sm text-gray-700">长期热点方法进入Tier 4，由C2编译器进行深度优化，编译时间长但性能最佳。</p>
                            </div>
                        </div>
                    </div>
                    
                    <div class="card bg-white p-6 rounded-lg shadow-sm">
                        <h3 class="section-title text-xl font-semibold mb-6">反馈机制与成本控制</h3>
                        <div class="grid md:grid-cols-2 gap-4">
                            <div class="p-3 bg-gray-50 rounded border border-gray-200">
                                <h4 class="font-medium text-sm mb-1">动态降级</h4>
                                <p class="text-xs text-gray-600">执行频率下降时从高Tier降级到低Tier，减少维护成本</p>
                            </div>
                            <div class="p-3 bg-gray-50 rounded border border-gray-200">
                                <h4 class="font-medium text-sm mb-1">异常回退</h4>
                                <p class="text-xs text-gray-600">编译后代码出现问题时可回退到低层级或解释执行</p>
                            </div>
                            <div class="p-3 bg-gray-50 rounded border border-gray-200">
                                <h4 class="font-medium text-sm mb-1">编译延迟</h4>
                                <p class="text-xs text-gray-600">高负载时延迟编译任务，避免影响应用性能</p>
                            </div>
                            <div class="p-3 bg-gray-50 rounded border border-gray-200">
                                <h4 class="font-medium text-sm mb-1">阈值调整</h4>
                                <p class="text-xs text-gray-600">通过JVM参数调整各层级切换阈值</p>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- 调优策略部分 -->
        <section id="optimization" class="mb-20">
            <div class="flex items-center mb-6">
                <div class="w-12 h-1 bg-gradient-to-r from-blue-400 to-purple-500 mr-4"></div>
                <h2 class="text-2xl font-semibold text-gray-800">分层编译的调优</h2>
            </div>
            
            <div class="grid md:grid-cols-2 gap-8">
                <div>
                    <div class="card bg-white p-6 rounded-lg shadow-sm mb-6">
                        <h3 class="section-title text-xl font-semibold mb-6">理解调优目标</h3>
                        <div class="space-y-4">
                            <div class="flex items-start">
                                <div class="flex-shrink-0 mt-1">
                                    <div class="flex items-center justify-center h-6 w-6 rounded-full bg-blue-100 text-blue-600">
                                        <i class="fas fa-bolt text-sm"></i>
                                    </div>
                                </div>
                                <div class="ml-3">
                                    <h4 class="font-medium">快速启动</h4>
                                    <p class="text-sm text-gray-600 mt-1">短生命周期应用更关注启动速度而非深度优化</p>
                                </div>
                            </div>
                            <div class="flex items-start">
                                <div class="flex-shrink-0 mt-1">
                                    <div class="flex items-center justify-center h-6 w-6 rounded-full bg-purple-100 text-purple-600">
                                        <i class="fas fa-stopwatch text-sm"></i>
                                    </div>
                                </div>
                                <div class="ml-3">
                                    <h4 class="font-medium">低延迟</h4>
                                    <p class="text-sm text-gray-600 mt-1">实时系统需避免编译带来的延迟</p>
                                </div>
                            </div>
                            <div class="flex items-start">
                                <div class="flex-shrink-0 mt-1">
                                    <div class="flex items-center justify-center h-6 w-6 rounded-full bg-green-100 text-green-600">
                                        <i class="fas fa-tachometer-alt text-sm"></i>
                                    </div>
                                </div>
                                <div class="ml-3">
                                    <h4 class="font-medium">高吞吐量</h4>
                                    <p class="text-sm text-gray-600 mt-1">长期运行服务可接受编译开销以换取更高性能</p>
                                </div>
                            </div>
                        </div>
                    </div>
                    
                    <div class="card bg-white p-6 rounded-lg shadow-sm">
                        <h3 class="section-title text-xl font-semibold mb-6">C1/C2编译器调优</h3>
                        <div class="space-y-4">
                            <div>
                                <h4 class="font-medium text-blue-600 mb-2">C1编译器优化</h4>
                                <ul class="list-disc pl-5 text-sm text-gray-700 space-y-1">
                                    <li><code>-XX:+PrintCompilation</code>: 查看方法编译情况</li>
                                    <li><code>-XX:UseFastEmptyMethods</code>: 优化空方法执行</li>
                                    <li><code>-XX:UseOnStackReplacement</code>: 启用栈上替换</li>
                                </ul>
                            </div>
                            <div>
                                <h4 class="font-medium text-purple-600 mb-2">C2编译器优化</h4>
                                <ul class="list-disc pl-5 text-sm text-gray-700 space-y-1">
                                    <li><code>-XX:CompileThresholdScaling</code>: 调整C2编译阈值</li>
                                    <li><code>-XX:+AggressiveOpts</code>: 启用高级优化选项</li>
                                    <li><code>-XX:+UseSuperWord</code>: 启用SIMD优化</li>
                                </ul>
                            </div>
                        </div>
                    </div>
                </div>
                
                <div>
                    <div class="card bg-white p-6 rounded-lg shadow-sm">
                        <h3 class="section-title text-xl font-semibold mb-6">编译层级控制</h3>
                        <div class="space-y-4">
                            <div class="p-4 bg-blue-50 rounded-lg">
                                <div class="flex items-center mb-2">
                                    <code class="bg-blue-100 text-blue-800 px-2 py-1 rounded text-sm mr-3">-XX:TieredStopAtLevel=3</code>
                                    <span class="font-medium">限制最高编译层级</span>
                                </div>
                                <p class="text-sm text-gray-700">避免C2编译开销，适合低延迟应用</p>
                            </div>
                            <div class="p-4 bg-purple-50 rounded-lg">
                                <div class="flex items-center mb-2">
                                    <code class="bg-purple-100 text-purple-800 px-2 py-1 rounded text-sm mr-3">-XX:CompileThreshold=1000</code>
                                    <span class="font-medium">调整编译触发阈值</span>
                                </div>
                                <p class="text-sm text-gray-700">增大值减少编译频率，适合短生命周期应用</p>
                            </div>
                            <div class="p-4 bg-green-50 rounded-lg">
                                <div class="flex items-center mb-2">
                                    <code class="bg-green-100 text-green-800 px-2 py-1 rounded text-sm mr-3">-XX:Tier3BackEdgeThreshold=50000</code>
                                    <span class="font-medium">控制循环优化阈值</span>
                                </div>
                                <p class="text-sm text-gray-700">调整循环触发Tier 3编译的条件</p>
                            </div>
                        </div>
                    </div>
                    
                    <div class="card bg-white p-6 rounded-lg shadow-sm mt-6">
                        <h3 class="section-title text-xl font-semibold mb-6">OSR(On-Stack Replacement)调优</h3>
                        <div class="grid md:grid-cols-2 gap-4">
                            <div class="p-3 bg-gray-50 rounded border border-gray-200">
                                <h4 class="font-medium text-sm mb-1"><code>-XX:OnStackReplacePercentage</code></h4>
                                <p class="text-xs text-gray-600">控制OSR触发时机，调整循环次数阈值</p>
                            </div>
                            <div class="p-3 bg-gray-50 rounded border border-gray-200">
                                <h4 class="font-medium text-sm mb-1"><code>-XX:LoopUnrollLimit</code></h4>
                                <p class="text-xs text-gray-600">控制循环展开深度，影响代码体积和性能</p>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </section>

        <!-- 与AOT编译对比部分 -->
        <section id="comparison" class="mb-20">
            <div class="flex items-center mb-6">
                <div class="w-12 h-1 bg-gradient-to-r from-blue-400 to-purple-500 mr-4"></div>
                <h2 class="text-2xl font-semibold text-gray-800">与AOT编译的对比</h2>
            </div>
            
            <div class="grid md:grid-cols-2 gap-8">
                <div>
                    <div class="card bg-white p-6 rounded-lg shadow-sm mb-6">
                        <h3 class="section-title text-xl font-semibold mb-6">基本概念对比</h3>
                        <div class="space-y-4">
                            <div>
                                <h4 class="font-medium text-blue-600 mb-2">分层编译</h4>
                                <p class="text-sm text-gray-700">
                                    动态编译技术，在运行时逐步将代码从解释执行提升到多层级JIT编译（C1/C2），利用运行时信息进行优化。
                                </p>
                            </div>
                            <div>
                                <h4 class="font-medium text-purple-600 mb-2">AOT编译</h4>
                                <p class="text-sm text-gray-700">
                                    静态编译技术，在程序启动前将字节码编译为机器码，不依赖运行时信息，直接执行预编译的本地代码。
                                </p>
                            </div>
                        </div>
                    </div>
                    
                    <div class="card bg-white p-6 rounded-lg shadow-sm">
                        <h3 class="section-title text-xl font-semibold mb-6">性能对比</h3>
                        <div class="space-y-4">
                            <div class="p-4 bg-blue-50 rounded-lg">
                                <h4 class="font-semibold mb-2">分层编译优势</h4>
                                <p class="text-sm text-gray-700">
                                    能够根据实际运行时行为进行深度优化，利用热点探测、动态信息收集等技术，提供针对性的性能改进。
                                </p>
                            </div>
                            <div class="p-4 bg-purple-50 rounded-lg">
                                <h4 class="font-semibold mb-2">AOT编译优势</h4>
                                <p class="text-sm text-gray-700">
                                    提供较低的启动开销，所有的编译工作已在运行前完成，特别适合对启动时间要求严格的应用场景。
                                </p>
                            </div>
                        </div>
                    </div>
                </div>
                
                <div>
                    <div class="card bg-white p-6 rounded-lg shadow-sm mb-6">
                        <h3 class="section-title text-xl font-semibold mb-6">详细对比表</h3>
                        <div class="overflow-x-auto">
                            <table class="comparison-table">
                                <thead>
                                    <tr>
                                        <th class="rounded-tl-lg">对比维度</th>
                                        <th>分层编译</th>
                                        <th class="rounded-tr-lg">AOT编译</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <tr>
                                        <td class="font-medium">编译时机</td>
                                        <td>运行时动态编译</td>
                                        <td>构建/部署前静态编译</td>
                                    </tr>
                                    <tr>
                                        <td class="font-medium">优化依据</td>
                                        <td>运行时信息</td>
                                        <td>静态分析</td>
                                    </tr>
                                    <tr>
                                        <td class="font-medium">启动速度</td>
                                        <td>较慢（需解释执行）</td>
                                        <td>较快（直接执行机器码）</td>
                                    </tr>
                                    <tr>
                                        <td class="font-medium">运行时性能</td>
                                        <td>可逐步优化至最高</td>
                                        <td>固定，无法动态优化</td>
                                    </tr>
                                    <tr>
                                        <td class="font-medium">资源消耗</td>
                                        <td>运行时占用编译资源</td>
                                        <td>无运行时编译开销</td>
                                    </tr>
                                    <tr>
                                        <td class="font-medium">适用场景</td>
                                        <td>长时间运行服务</td>
                                        <td>启动关键型应用</td>
                                    </tr>
                                </tbody>
                            </table>
                        </div>
                    </div>
                    
                    <div class="card bg-white p-6 rounded-lg shadow-sm">
                        <h3 class="section-title text-xl font-semibold mb-6">适用场景总结</h3>
                        <div class="grid md:grid-cols-2 gap-4">
                            <div class="p-4 bg-blue-50 rounded-lg">
                                <h4 class="font-semibold text-blue-600 mb-2">分层编译适合</h4>
                                <ul class="list-disc pl-5 text-sm text-gray-700 space-y-1">
                                    <li>长时间运行的服务器应用</li>
                                    <li>需要动态调整性能的应用</li>
                                    <li>开发和调试阶段</li>
                                </ul>
                            </div>
                            <div class="p-4 bg-purple-50 rounded-lg">
                                <h4 class="font-semibold text-purple-600 mb-2">AOT编译适合</h4>
                                <ul class="list-disc pl-5 text-sm text-gray-700 space-y-1">
                                    <li>启动时间关键的应用</li>
                                    <li>资源受限环境</li>
                                    <li>分发和部署场景</li>
                                </ul>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </section>
    </main>

    <!-- 页脚 -->
    <footer class="bg-gray-900 text-white py-10">
        <div class="container mx-auto px-6">
            <div class="flex flex-col items-center">
                <div class="text-lg font-medium mb-2">技术小馆</div>
                <a href="http://www.yuque.com/jtostring" class="footer-link text-gray-400 hover:text-gray-300 transition duration-300">http://www.yuque.com/jtostring</a>
            </div>
        </div>
    </footer>

    <script>
        mermaid.initialize({
            startOnLoad: true,
            theme: 'default',
            flowchart: {
                useMaxWidth: true,
                htmlLabels: true,
                curve: 'basis'
            }
        });
    </script>
</body>
</html>
```